package sort;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author XY
 * @version 1.0
 * @date 2022/2/14 9:13
 * @Description
 */
public class Leet217 {

    //O(n2)
    public boolean containsDuplicate1(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            for (int j = i+1; j < nums.length; j++) {
                if(num == nums[j]){
                    return true;
                }
            }
        }
        return false;
    }

    public boolean containsDuplicate(int[] nums) {
        Set<Integer> set = new HashSet<>();
        Arrays.sort(nums);
        for (int num : nums) {
            if(!set.add(num)){
                return true;
            }
        }
        return false;
    }




}
